
#include <iostream>
#include <memory>
#include <string>

// Step 1: 抽象原型类 - 定义角色的基本接口
class Character {
public:
    virtual ~Character() = default;

    // 定义克隆方法，返回当前对象的副本
    virtual std::unique_ptr<Character> clone() const = 0;

    // 定义展示角色信息的方法
    virtual void showInfo() const = 0;

protected:
    std::string name;
    int health;
    int attackPower;
};

// Step 2: 具体原型类 - 战士角色
class Warrior : public Character {
public:
    Warrior(const std::string& name, int health, int attackPower) {
        this->name = name;
        this->health = health;
        this->attackPower = attackPower;
    }

    // 实现克隆方法，返回战士的副本
    std::unique_ptr<Character> clone() const override {
        return std::make_unique<Warrior>(*this);
    }

    // 展示战士信息
    void showInfo() const override {
        std::cout << "Warrior Name: " << name << ", Health: " << health << ", Attack Power: " << attackPower << std::endl;
    }
};

// Step 3: 具体原型类 - 法师角色
class Mage : public Character {
public:
    Mage(const std::string& name, int health, int attackPower) {
        this->name = name;
        this->health = health;
        this->attackPower = attackPower;
    }

    // 实现克隆方法，返回法师的副本
    std::unique_ptr<Character> clone() const override {
        return std::make_unique<Mage>(*this);
    }

    // 展示法师信息
    void showInfo() const override {
        std::cout << "Mage Name: " << name << ", Health: " << health << ", Attack Power: " << attackPower << std::endl;
    }
};

// 客户端代码
int main() {
    // 创建初始角色原型
    std::unique_ptr<Character> warriorPrototype = std::make_unique<Warrior>("Warrior Prototype", 100, 20);
    std::unique_ptr<Character> magePrototype = std::make_unique<Mage>("Mage Prototype", 80, 30);

    // 克隆战士角色并调整属性
    std::unique_ptr<Character> warrior1 = warriorPrototype->clone();
    warrior1->showInfo();

    std::unique_ptr<Character> warrior2 = warriorPrototype->clone();
    warrior2->showInfo();

    // 克隆法师角色并调整属性
    std::unique_ptr<Character> mage1 = magePrototype->clone();
    mage1->showInfo();

    std::unique_ptr<Character> mage2 = magePrototype->clone();
    mage2->showInfo();

    return 0;
}


